#ifndef ALARMRECORD_H
#define ALARMRECORD_H

#include <QString>
#include <QDateTime>

/**
 * @brief 报警记录实体类
 * @details 对应数据库 alarm_records 表
 */
class AlarmRecord
{
public:
    // 报警类型枚举
    enum AlarmType
    {
        OverTemperature,  // 超温
        OverPressure,     // 超压
        OverFlow,         // 超流
        Offline,          // 离线
        Recovered,        // 恢复
        StatusChange      // 状态变化
    };

    // 报警级别枚举
    enum AlarmLevel
    {
        Info,     // 信息通知
        Warning,  // 警告报警
        Critical  // 严重报警
    };

    AlarmRecord();
    AlarmRecord(const QString &deviceId, AlarmType type, AlarmLevel level);

    // Getter 方法
    int id() const { return m_id; }
    QString deviceId() const { return m_deviceId; }
    QDateTime timestamp() const { return m_timestamp; }
    AlarmType alarmType() const { return m_alarmType; }
    AlarmLevel alarmLevel() const { return m_alarmLevel; }
    QString paramName() const { return m_paramName; }
    double paramValue() const { return m_paramValue; }
    double threshold() const { return m_threshold; }
    QString description() const { return m_description; }
    bool isAcknowledged() const { return m_acknowledged; }
    QString acknowledgedBy() const { return m_acknowledgedBy; }
    QDateTime acknowledgedAt() const { return m_acknowledgedAt; }

    // Setter 方法
    void setId(int id) { m_id = id; }
    void setDeviceId(const QString &deviceId) { m_deviceId = deviceId; }
    void setTimestamp(const QDateTime &timestamp) { m_timestamp = timestamp; }
    void setAlarmType(AlarmType type) { m_alarmType = type; }
    void setAlarmLevel(AlarmLevel level) { m_alarmLevel = level; }
    void setParamName(const QString &paramName) { m_paramName = paramName; }
    void setParamValue(double value) { m_paramValue = value; }
    void setThreshold(double threshold) { m_threshold = threshold; }
    void setDescription(const QString &description) { m_description = description; }
    void setAcknowledged(bool acknowledged) { m_acknowledged = acknowledged; }
    void setAcknowledgedBy(const QString &by) { m_acknowledgedBy = by; }
    void setAcknowledgedAt(const QDateTime &at) { m_acknowledgedAt = at; }

    // 工具方法
    QString alarmTypeString() const;
    QString alarmLevelString() const;
    bool isValid() const { return !m_deviceId.isEmpty(); }

    // 静态转换方法
    static AlarmType stringToAlarmType(const QString &str);
    static AlarmLevel stringToAlarmLevel(const QString &str);

private:
    int m_id;                    // 自增主键
    QString m_deviceId;          // 设备 ID
    QDateTime m_timestamp;       // 报警/事件时间
    AlarmType m_alarmType;       // 报警类型
    AlarmLevel m_alarmLevel;     // 报警级别
    QString m_paramName;         // 参数名称
    double m_paramValue;         // 触发报警的实际值
    double m_threshold;          // 报警阈值
    QString m_description;       // 报警描述
    bool m_acknowledged;         // 是否已确认
    QString m_acknowledgedBy;    // 确认人
    QDateTime m_acknowledgedAt;  // 确认时间
};

#endif // ALARMRECORD_H

